package com.qing.dish;

import java.util.Arrays;
import java.util.Comparator;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors.*;

import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.partitioningBy;
import static java.util.stream.Collectors.toList;

public class Demo5 {


	private static List<Dish> menu= Arrays.asList(
			new Dish("黄焖鸡米饭",false,15,"肉"),
			new Dish("水煮鱼",true,12,"鱼"),
			new Dish("酸菜鱼",false,20,"鱼"),
			new Dish("脆皮鸡米饭",false,18,"米饭"),
			new Dish("麻辣香锅",true,32,"米饭"),
			new Dish("鸡公煲",false,20,"肉"),
			new Dish("汉堡王",true,100,"米饭"),
			new Dish("至尊牛排",false,20,"肉"),
			new Dish("蛋炒饭",true,12,"素"),
			new Dish("咖喱",false,29,"米饭"),
			new Dish("炒白菜",false,8,"素"),
			new Dish("炒萝卜",false,9,"素"),
			new Dish("烤肉",true,50,"肉")
	);
	public static void main(String[] args) {
		Map<Boolean,List<Dish>> map=menu.stream().collect(partitioningBy(Dish::isVegetarian));
		map.get(true).forEach(System.out::println);
		System.out.println("----------等同：----------------");
		menu.stream().filter(Dish::isVegetarian).collect(toList()).forEach(System.out::println);

		System.out.println("------------------------");
		Map<Boolean,Map<Boolean,List<Dish>>> map3=menu.stream().collect(partitioningBy(Dish::isVegetarian,
				partitioningBy(dish -> dish.getCalories()>20)
				));
		System.out.println("------------分组 数量------------");
		menu.stream().collect(partitioningBy(Dish::isVegetarian,counting()));
	}
}
